<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %>
<%@ page language="java" import="java.util.*" pageEncoding="utf-8"%>
<%@ page contentType="text/html;charset=utf-8" %>

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<title>Admin Template </title>
<%@ include file="include.jsp"%>

<script type="text/javascript">
$(document).ready(function(){
	
	/* setup navigation, content boxes, etc... */
	Administry.setup();
	
	/* datatable */
	$('#example').dataTable();
	
	
	new nicEditor({iconsPath : 'http://localhost:8080/adminpanel/img/nicEditorIcons.gif'}).panelInstance('productdesc');
	
	$("#add").click(function() {
		//alert('aa');
  		$('#thickboxId').click();
  	});
  	
  	$("#del").click(function() {
  		var str=[];

        $("input[name='checkbox']").each(function() {

	        if($(this).attr("checked")){
				
		        str.push($(this).val());
		        
			}

        });
        
       
 			var url = "http://localhost:8080/adminpanel/myinfo/delproduct?delid=";
 			var fullRequest = url+str;
 			jQuery.ajax({
	 			url: fullRequest,
			  	type:"POST",
			  	//beforeSend:loading,
			    success: function(msg){  
     				alert( "Data del: " + msg );  
   				}
			});
        
       
     });

 	
  	
	var oShi = $("#productcat");
	
		
		
		    oShi.empty();
			$.getJSON("http://localhost:8080/adminpanel/myinfo/getpt", function(data) {
					
					 
  			    	
  			    	for (i = 0; i < data.mypts.length; i++) {
    
      					$("<option value='" + data.mypts[i].type + "'>" + data.mypts[i].type + "</option>").appendTo(oShi)
      					
      				}
					
					
					
					
			});
				
	
	
	
		var validator = $("#productform").validate({
		rules: {
			
			productid: {
				required: true,
				minlength: 3,
				remote: {  
      			url: "/adminpanel/myinfo/checkProductId",     //后台处理程序  
      			type: "post",               //数据发送方式  
      			dataType: "json",           //接受数据格式     
      			data: {                     //要传递的数据，默认已传递应用此规则的表单项  
          			product_id: function() {  
              			return $("#product_id").val();  
          			}  
      			}  
			   }
			},	
			
			productname: {
				required: true,
				minlength: 3,
				remote: {  
      			url: "/adminpanel/myinfo/checkProductName",     //后台处理程序  
      			type: "post",               //数据发送方式  
      			dataType: "json",           //接受数据格式     
      			data: {                     //要传递的数据，默认已传递应用此规则的表单项  
          			product_name: function() {  
              			return $("#product_name").val();  
          			}  
      			}  
			   }
			},
			
			
		},
		messages: {
			
			productid: {
				required: "Enter a productid",
				minlength: jQuery.format("Enter at least {0} characters"),
				remote:"this ID can not use"
			},
			productname: {
				required: "Provide a producttitle",
				rangelength: jQuery.format("Enter at least {0} characters"),
				remote:"this Name can not use"
			},
		
			
		},
		// the errorPlacement has to take the layout into account
		errorPlacement: function(error, element) {
			error.insertAfter(element.parent().find('label:first'));
		},
		// specifying a submitHandler prevents the default submit, good for the demo
		
		// set new class to error-labels to indicate valid fields
		success: function(label) {
			// set &nbsp; as text for IE
			label.html("&nbsp;").addClass("ok");
		}
	});

	});
	
</script>




</head>
<body>


	<%@ include file="header.jsp"%>
	<!-- Page content -->
	<div id="page">
		<!-- Wrapper -->
		<div class="wrapper">
				<!-- Left column/section -->
				<section class="column width6 first">					
					

					
					<div class="clear">&nbsp;</div>
					
					<h3>Data tables</h3>
<!--					<a href="#" class="btn" id="cm"><span class="icon icon-add">&nbsp;</span>Add New</a>-->
					<input name="add" id="add" type="button" class="btn" value="Add New" />
					<input name="del" id="del" type="button" class="btn" value="Del" />
<!--					<a href="#ap" class="nyroModal">Inline content</a><br />-->
					<a id="thickboxId" a href="#ap"  class="nyroModal" title=""></a>
					<div id='ap' style='display: none;'><%@ include file="addproduct.jsp"%></div>
					
					<table class="display stylized" id="example">
						<thead>
							<tr>
								<th>ID</th>
								<th>Product_ID</th>
								<th>Product_Name</th>
								<th>Product_describe</th>
								<th>Product_type</th>
								<th>Product_vendor</th>
								<th>CreateTime</th>
								<th>operate</th>
							</tr>
						</thead>
						<tbody>
							<c:forEach items="${products}" var="product">
	
								<tr>
									
									<td>
										<c:out value="${product.id}" />
									</td>
									
									<td>
										<c:out value="${product.product_id}" />
									</td>
									
									
									<td> 
										<c:out value="${product.product_name}" />
									</td>
									
									
									<td>
										<a href="http://localhost:8080/adminpanel/myinfo/showproduct?id=${product.id}" class="nyroModal">click to detail</a>
									</td>
									
									
									<td>
										<c:out value="${product.product_type}" />
									</td>
									
									
									<td>
										<c:out value="${product.product_vendor}" />
									</td>
									
									
									<td>
										<c:out value="${product.create_time}" />
									</td>
									
									<td>
										<input type="checkbox" name="checkbox" value="${product.id}" />
									</td>
								
	
								</tr>
							</c:forEach>
						</tbody>

				</table>
					
					<div class="clear">&nbsp;</div>
					
				</section>
				<!-- End of Left column/section -->
				
			
				
				
				
		</div>
		<!-- End of Wrapper -->
	</div>
	<!-- End of Page content -->
	
	<%@ include file="footer.jsp"%>

</body>
</html>
